

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="zh" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="zh" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>optuna.importance &mdash; Optuna 1.4.0 文档</title>
  

  
  
    <link rel="shortcut icon" href="../../_static/favicon.ico"/>
  
  
  

  
  <script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/jquery.js"></script>
        <script src="../../_static/underscore.js"></script>
        <script src="../../_static/doctools.js"></script>
        <script src="../../_static/language_data.js"></script>
        <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    
    <script type="text/javascript" src="../../_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" />
    <link rel="index" title="索引" href="../../genindex.html" />
    <link rel="search" title="搜索" href="../../search.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../index.html" class="icon icon-home"> Optuna
          

          
          </a>

          
            
            
              <div class="version">
                1.4.0
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">目录</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../installation.html">安装</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../tutorial/index.html">教程</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../reference/index.html">API Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../faq.html">常见问题</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../index.html">Optuna</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../index.html">模块代码</a> &raquo;</li>
        
      <li>optuna.importance</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>optuna.importance 源代码</h1><div class="highlight"><pre>
<span></span><span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Dict</span>
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">List</span>
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Optional</span>

<span class="kn">from</span> <span class="nn">optuna._experimental</span> <span class="kn">import</span> <span class="n">experimental</span>
<span class="kn">from</span> <span class="nn">optuna.importance._base</span> <span class="kn">import</span> <span class="n">BaseImportanceEvaluator</span>
<span class="kn">from</span> <span class="nn">optuna.importance._fanova</span> <span class="kn">import</span> <span class="n">FanovaImportanceEvaluator</span>  <span class="c1"># NOQA</span>
<span class="kn">from</span> <span class="nn">optuna.importance._mean_decrease_impurity</span> <span class="kn">import</span> <span class="n">MeanDecreaseImpurityImportanceEvaluator</span>
<span class="kn">from</span> <span class="nn">optuna.study</span> <span class="kn">import</span> <span class="n">Study</span>


<div class="viewcode-block" id="get_param_importances"><a class="viewcode-back" href="../../reference/importance.html#optuna.importance.get_param_importances">[文档]</a><span class="nd">@experimental</span><span class="p">(</span><span class="s2">&quot;1.3.0&quot;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">get_param_importances</span><span class="p">(</span>
    <span class="n">study</span><span class="p">:</span> <span class="n">Study</span><span class="p">,</span> <span class="n">evaluator</span><span class="p">:</span> <span class="n">BaseImportanceEvaluator</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">params</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]]</span> <span class="o">=</span> <span class="kc">None</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">float</span><span class="p">]:</span>
    <span class="sd">&quot;&quot;&quot;Evaluate parameter importances based on completed trials in the given study.</span>

<span class="sd">    The parameter importances are returned as a dictionary where the keys consist of parameter</span>
<span class="sd">    names and their values importances.</span>
<span class="sd">    The importances are represented by floating point numbers that sum to 1.0 over the entire</span>
<span class="sd">    dictionary.</span>
<span class="sd">    The higher the value, the more important.</span>
<span class="sd">    The returned dictionary is of type :class:`collections.OrderedDict` and is ordered by</span>
<span class="sd">    its values in a descending order.</span>

<span class="sd">    If ``params`` is :obj:`None`, all parameter that are present in all of the completed trials are</span>
<span class="sd">    assessed.</span>
<span class="sd">    This implies that conditional parameters will be excluded from the evaluation.</span>
<span class="sd">    To assess the importances of conditional parameters, a :obj:`list` of parameter names can be</span>
<span class="sd">    specified via ``params``.</span>
<span class="sd">    If specified, only completed trials that contain all of the parameters will be considered.</span>
<span class="sd">    If no such trials are found, an error will be raised.</span>

<span class="sd">    If the given study does not contain completed trials, an error will be raised.</span>

<span class="sd">    .. note::</span>

<span class="sd">        If ``params`` is specified as an empty list, an empty dictionary is returned.</span>

<span class="sd">    .. seealso::</span>

<span class="sd">        See :func:`~optuna.visualization.plot_param_importances` to plot importances.</span>

<span class="sd">    Args:</span>
<span class="sd">        study:</span>
<span class="sd">            An optimized study.</span>
<span class="sd">        evaluator:</span>
<span class="sd">            An importance evaluator object that specifies which algorithm to base the importance</span>
<span class="sd">            assessment on.</span>
<span class="sd">            Defaults to</span>
<span class="sd">            :class:`~optuna.importance._mean_decrease_impurity.MeanDecreaseImpurityImportanceEvaluator`.</span>
<span class="sd">        params:</span>
<span class="sd">            A list of names of parameters to assess.</span>
<span class="sd">            If :obj:`None`, all parameters that are present in all of the completed trials are</span>
<span class="sd">            assessed.</span>

<span class="sd">    Returns:</span>
<span class="sd">        An :class:`collections.OrderedDict` where the keys are parameter names and the values are</span>
<span class="sd">        assessed importances.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">evaluator</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
        <span class="n">evaluator</span> <span class="o">=</span> <span class="n">MeanDecreaseImpurityImportanceEvaluator</span><span class="p">()</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">evaluator</span><span class="p">,</span> <span class="n">BaseImportanceEvaluator</span><span class="p">):</span>
        <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s2">&quot;Evaluator must be a subclass of BaseImportanceEvaluator.&quot;</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">evaluator</span><span class="o">.</span><span class="n">evaluate</span><span class="p">(</span><span class="n">study</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="n">params</span><span class="p">)</span></div>
</pre></div>

           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2018, Optuna Contributors.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
    <a href="../../privacy.html">Privacy Policy</a>.
     


</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
    <!-- Theme Analytics -->
    <script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-55135190-8', 'auto');
    ga('send', 'pageview');
    </script>

    
   

</body>
</html>